//
//  XinLiCePingListVC.m
//  students
//
//  Created by 任辰东 on 2024/2/27.
//

#import "XinLiCePingListVC.h"
#import "XinLiCePingTCell.h"
#import "XinLiCePingApis.h"
#import "XinLiCePingTestListVC.h"

@interface XinLiCePingListVC ()

@end

@implementation XinLiCePingListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"心理测评";
    
    [self setupEstimatedRowHeight:200 cellClasses:@[[XinLiCePingTCell class]]];
    [self beginRefresh];
    
    self.myTableView.mj_footer = nil;
}

-(void)requestDataWithOffset:(NSInteger)offset success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure
{
    NSDictionary *params = @{
        @"organ_id":[GVUserDefaults standardUserDefaults].organ_id,
        @"student_id":[GVUserDefaults standardUserDefaults].student_id
        
//        @"organ_id":@"1281",
//        @"student_id":@"5139"
    };
    
    WeakSelf
    [self showLoadingHUDWithMessage:nil];
    [XinLiCePingApis CepingListRequestWithParams:params SuccessBlock:^(NSNumber *code, NSString *msg, id responseData) {
        StrongSelf
        [self hideLoadingHUD];
        DLog(@"responseData === %@",responseData);
        NSMutableArray *data = [XinLiCePingListModel mj_objectArrayWithKeyValuesArray:responseData];
        success(data);
        [self addEmptyView];
        
    } FailureBlock:^(NSNumber *code, NSString *msg) {
    StrongSelf
        [self showWarningHUDWithMessage:msg completion:NULL];
    }];
   
}

- (void)configCellSubViewsCallback:(XinLiCePingTCell *)cell indexPath:(NSIndexPath *)indexPath
{

    XinLiCePingListModel *model;
    if (indexPath.row < self.dataSourceArr.count) {
        model = self.dataSourceArr[indexPath.row];
    }
    
    WeakSelf
    [cell setFunctionBtnClicked:^{
        
        StrongSelf
        XinLiCePingTestListVC *testVC = [[XinLiCePingTestListVC alloc]initWithModel:model];
        [self.navigationController pushViewController:testVC animated:YES];
        

        [testVC setSubmitSuccessBlock:^{
            StrongSelf
            [self beginRefresh];
        }];
    }];
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    XinLiCePingListModel *model;
    if (indexPath.row < self.dataSourceArr.count) {
        model = self.dataSourceArr[indexPath.row];
    }
    
    XinLiCePingTestListVC *testVC = [[XinLiCePingTestListVC alloc]initWithModel:model];
    [self.navigationController pushViewController:testVC animated:YES];
    
    WeakSelf
    [testVC setSubmitSuccessBlock:^{
        StrongSelf
        [self beginRefresh];
    }];

}

-(void)addEmptyView
{
    if (IsEmpty(self.dataSourceArr)) {
        [RCDEmptyView addEmptyWithStyle:EmptyViewStyleCommon onView:self.myTableView position:EmptyViewPositionCenter clickCallBack:nil];
    }else{
        [RCDEmptyView removeFromParentView:self.myTableView];
    }
}

@end
